<div class="easyui-panel" data-options="fit:true,border:false" style="padding:10px;">
    <div class="easyui-layout" fit='true' style="width:700px;height:350px;">
        <div data-options="region:'north',collapsed:true" style="height:90px; padding-top:10px;" title="检索选项">
            <form id="worklog_ff" method="post">
                <table cellpadding="5">
                    <tr>
                    	<td align="right">关键字: </td>
                        <td><input id="worklog_advanced_search_key" class="easyui-textbox" type="text" style="width:300px;"></td>
                        <td align="right">开始时间:</td>
                        <td><input id="worklog_ids" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#worklog_calendar_id',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).datebox('clear');}}]" style="width:200px; height:24px;"></td>
                        <td align="right">结束时间:</td>
                        <td><input id="worklog_ide" class="easyui-datebox" editable="false" data-options="sharedCalendar:'#worklog_calendar_id',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).datebox('clear');}}]" style="width:200px; height:24px;"></td>
                        <td></td>
                        <td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="worklog_search_submit('worklog')">搜索</a>
                        <div id="worklog_calendar_id" class="easyui-calendar"></div></td>
                    </tr>             
                </table>
                
            </form>
        </div>
        <div data-options="region:'center'" title="检索结果">
            <table id="worklog_list"></table>
            <div id="worklogboxtoolbar" style="padding:5px;height:auto">
                <div>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="$.cachedScript('<?php echo base_url('data/other/js/worklog.js')?>').done(function () { new_worklog(new Date())}); ">添加今天日志</a>
                    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del_worklog_list()">删除</a>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
$('#worklog_ids').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date>d1){
			$('#worklog_ids').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','开始日期不能大于当前日期','warning');
		}
	}
});
$('#worklog_ide').datebox({
	onSelect: function (date) {
		var now = new Date();
        var d1 = new Date(now.getFullYear(), now.getMonth(), now.getDate());
		if(date>d1){
			$('#worklog_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不能大于当前日期','warning');
		}
		var eids = $("#worklog_ids").datebox('getValue');
		var newDt=new Date(eids.replace("-","/")); 
		if(eids != '' && date<newDt){
			$('#worklog_ide').datebox('setValue', '');	// set datebox value
			$.messager.alert('警告','结束日期不能小于开始日期','warning');
		}
	}
});


function worklog_search_submit(m){
	var queryParams = $('#'+m+'_list').datagrid('options').queryParams;  
		if($("#"+m+"_advanced_search_key").val())
			queryParams.key = $("#"+m+"_advanced_search_key").val();
		else
			delete queryParams.key;
		if($("#"+m+"_ids").datebox('getValue'))
			queryParams.wids = $("#"+m+"_ids").datebox('getValue');
		else
			delete queryParams.wids;
		if($("#"+m+"_ide").datebox('getValue'))
			queryParams.wide = $("#"+m+"_ide").datebox('getValue');
		else
			delete queryParams.wide;

	$('#'+m+'_list').datagrid('options').queryParams=queryParams;        
	$('#'+m+'_list').datagrid('reload'); 
}


//待办工作数据构造方法，包括列表属性设置，字段设置，双击设置

$('#worklog_list').datagrid({
	url:'<?php echo base_url('worklog/log_data');?>',
	singleSelect:true,
	rownumbers:true,
	pagination:true,
	pageSize:50,
	pageList:[30,50,100],
	fit:true,
	fitColumns:true,
	border:false,
	queryParams:{},
	sortName:'log_date',
	sortOrder:'desc',
	toolbar:'#worklogboxtoolbar',
	columns:[[
		{field:'id',hidden:'true'},
		{field:'log_date',title:'日期',width:50,align:'center',sortable:'true'},
		{field:'log_w',title:'星期',width:30,align:'center'},
		{field:'log_am',title:'上午',width:200},
		{field:'log_pm',title:'下午',width:200},
		{field:'log_morn',title:'明天预安排',width:200}
	]],
	onDblClickRow:function(index,data){
		var str = data.log_date.replace(/-/g,'/'); 
		var date = new Date(str); 
		//var time = date.getTime();		
		//$.getScript('<?php echo base_url('data/other/js/worklog.js')?>',function(){new_worklog(date)});
		$.cachedScript('<?php echo base_url('data/other/js/worklog.js')?>').done(function () { new_worklog(date)}); 
	},
	onLoadSuccess:function(data){ 
		var pager = $(this).datagrid('getPager');
			pager.pagination({
				displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
			});
	}
});	



function del_worklog_list(){
	var getobj = $('#worklog_list').datagrid("getChecked");
	var getid = [];

	$.each(getobj, function(index, item){
		getid.push(item.id);
	}); 

	if(getid.length == 0){
		$.messager.alert('提示','要删除工作日志，请选取要操作的行','warning');
	}else{
		$.messager.confirm('提示', '确定要删除选中的工作日志吗?', function(r){
			if(r){
				$.post(PROJECT_PATH+'worklog/log_del',{getid:getid},function(result){
					if(result.success){
						$('#worklog_list').datagrid('reload');
					}else{
						$.messager.alert('错误',result.errorMsg,'error');
					}
				},'json');
			}
		});	
	}
}
</script>